﻿using HandyControl.Controls;
using HandyControl.Tools.Extension;

using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Tryit.ViewModels;
using MessageBox = HandyControl.Controls.MessageBox;
using Window = System.Windows.Window;

namespace Tryit.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class HomeWindow : Window
    {
        private HomeWindowViewModel vm;
        public HomeWindow()
        {
            InitializeComponent();
            vm = DataContext as HomeWindowViewModel;
            ClapseShow.Hide();
        }

        private void BtMin_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void BtMax_Click(object sender, RoutedEventArgs e)
        {
            if (WindowState == WindowState.Normal) WindowState = WindowState.Maximized;
            else WindowState = WindowState.Normal;
        }

        private void BtClose_Click(object sender, RoutedEventArgs e)
        {
            // 弹出确认对话框
            MessageBoxResult result = MessageBox.Show("您确定要退出程序吗？",
                "提示(选否自动最小化窗口)", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                Application.Current.Shutdown(); // 退出程序
            }
            else Hide();
        }

        private void NotifyIcon_Click(object sender, RoutedEventArgs e)
        {
            this.Show();
        }


        /// <summary>
        /// 只有在收缩栏关闭时才进行Tooltip
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SideMenuItem_MouseEnter(object sender, MouseEventArgs e)
        {
            var sideMenuItem = sender as SideMenuItem;
            if (vm != null)
            {
                if (vm.IsClapsed)
                {
                    sideMenuItem.ToolTip = sideMenuItem.Header.ToString();
                }
                else sideMenuItem.ToolTip = null;
            }

        }
        /// <summary>
        /// 是否隐藏标题栏图标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (vm != null)
            {
                if (!vm.IsClapsed)
                {
                    ClapseShow.Show();
                    ExpandShow.Hide();
                }
                else
                {
                    ExpandShow.Show();
                    ClapseShow.Hide();
                }
            }
        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if(e.ButtonState == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }
    }
}
